package com.travel.find.findadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.travel.R;
import com.travel.find.findbean.ListBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/20.
 * bourn 的gridview适配器
 */
public class BournGVAdapter extends BaseAdapter {
    private List<ListBean> hotList;
    private Context context;
    //判断是否点击查看更多
    private boolean i;
    public BournGVAdapter(Context context, List<ListBean> hotList,boolean i) {
        this.context = context;
        this.hotList = hotList;
        this.i=i;
    }

    @Override
    public int getCount() {
        if(hotList.size()>6){
            if(i){
                return hotList.size();
            }else {
                return 6;
            }
        }else {
            return hotList.size();
        }
    }

    @Override
    public Object getItem(int i) {
        return hotList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view==null) {
            view = LayoutInflater.from(context).inflate(R.layout.gv_bourn_item, viewGroup, false);
            holder=new ViewHolder(view);
            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        holder.tvBournItem.setText(hotList.get(i).getCnName());
        Glide.with(context).load(hotList.get(i).getPic()).into(holder.ivBournItem);
//        Log.e("tag","@@@@@@@@@@@@@@@@@@@@@@@@@@2"+hotList.size());
        return view;
    }

    static class ViewHolder {
        @Bind(R.id.iv_bourn_item)
        ImageView ivBournItem;
        @Bind(R.id.tv_bourn_item)
        TextView tvBournItem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
    public void rush(boolean isClear){
        i=isClear;
        notifyDataSetChanged();
    }
}
